import { Inject, Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { DoctorInfoEntity } from '../entity/info';

/**
 * 医生信息
 */
@Provide()
export class DoctorInfoService extends BaseService {
  @InjectEntityModel(DoctorInfoEntity)
  doctorInfoEntity: Repository<DoctorInfoEntity>;

  async getSelectlist(shopId: number) {
    const users = await this.doctorInfoEntity.find({
      where: {
        ...(shopId !== 0 ? { shop: shopId } : {}),
        status: 1,
      }
    });
    return users.map(doctor => ({
      label: doctor.name,
      value: doctor.id
    }));
  }
}
